package login;

import java.util.ArrayList;
import java.util.List;

import com.rORM.core.Query;
import com.rORM.core.QueryFactory;

import database.Password;
import database.Teacher;
/**
 * 核对登录账号密码
 * @author windyrjc
 *
 */
public class Check { 
	private int user;
	private String pwd;
	private int flag;//判断传入的是老师还是学生 1代表学生 其他数字代表老师
	public Check(int user,String pwd){
		this.user = user;
		this.pwd = pwd;
	}
	
	
	@SuppressWarnings("unchecked")
/**
 * 核对学生信息	
 */
	public boolean CheckStu(){
		
//		try{
			Query q = QueryFactory.createQuery();
			List <Password> list = new ArrayList<Password>();
			list = q.queryRows("select * from password",Password.class, null);
			for(Password pwd:list){
				if(pwd.getStuuser() == null && pwd.getStupwd() == null){
					continue;
				}
				if(pwd.getStuuser().equals(user) && pwd.getStupwd().equals(this.pwd)){ 
					System.out.println("login student success!");
					return true;
				}
			}
//		}catch(Exception e){
//			return false;
//		}
		return false;
	}
	public String getUserName(int id){
		
		Query q = QueryFactory.createQuery();
		Teacher t  = (Teacher)q.queryUniqueRow("select * from teacher where teacherID =?", Teacher.class, new Object[]{id});
		return t.getName();
		
	}


/**
 *核对老师信息
 */	
	public boolean CheckTea(){
//		try{
			Query q = QueryFactory.createQuery();
			List <Password> list = new ArrayList<Password>();
			list = q.queryRows("select * from password",Password.class, null);
			for(Password pwd:list){
				if(pwd.getTeauser() == null && pwd.getTeapwd() == null){
					continue;
				}
				if(pwd.getTeauser().equals(user) && pwd.getTeapwd().equals(this.pwd)){
					System.out.println("login teacher success!");
					return true;
				}
			}
//		}catch(Exception e){
//			return false;
//		}
		return false;
	}
	
	public static void main(String args[]){
	}
}

